package be.djdb.game.essetials;


import java.awt.Image;
import java.util.logging.Level;
import java.util.logging.Logger;


import be.djdb.Statics;

public class MyPlayer {
	private int lives;
	private int score;
    private int speed =0;
    private Skins skin;
    protected Direction direction;
	protected MyPos actualposition;
	private int animationslower;
	protected boolean logme=false;
	public MyPlayer(int lifes,Skins skin) {
		this.lives= lifes;
		score = 0;
    	int x= MyLevel.blocksize*5;
    	int y=  MyLevel.blocksize*9;
		actualposition =new MyPos(x,y);
		System.out.println(skin.getClass().getName()+actualposition.toString());
		direction = Direction.FIXED;
		this.skin = skin;
	}
	public void die(){
		if(this.haslives())--lives;
	}
	public boolean haslives(){
	   return  lives!= 0;
	}
	public void addscore(int points){
		score +=points;
	}
	public Image getface(){
    		return skin.getfaceimage(direction);  	
    }
	private static  void log(Level level, String msg ){
	    String tag =new String("<>>>>*"+Statics.LIBNAME+"-"+Statics.COPYRIGHTBY+"*<<<<>");
	    Logger.getLogger(MyPlayer.class.getName()).log(level, tag + msg);
	}
	public int getlives(){
		return lives;
	}
	public int getscore(){
		return score;
	}
    public Skins getSkin() {
        return skin;
    }
	public void setSpeed(int speed) {
		this.speed= speed;
	}
	public void setDirection(Direction dir) {
				direction =dir;
	}
	public MyPos getpos() {
		return actualposition;
	}
	public void animate() {
		skin.animate();
	}
	public void move(){
		if (canmove()){
			actualposition.move(direction,speed);
		}else{
			if(logme){	log(Level.FINE,"one of the players cannot move");}
		}
	}
	public void setActualposition(MyPos actualposition) {
		this.actualposition =actualposition;
	}
	public boolean canmove(){
		return speed!=0;
	}
	public Direction getdirection() {
		return direction;
	}
	public void annimate(int timerval){
		int time = timerval-MyLevel.blocksize+10;
		if (time<1){
			skin.animate();
		}else if (time>animationslower){
			animationslower = 0;
			skin.animate();
		}else {
			animationslower= animationslower+2;
		}
	}
	@Override
	public String toString() {
		return new String(" Myplayer[Lives:"+lives+"score"+score+"skin:"+this.skin.getClass().getName()+actualposition.toString()+"Direction:"+this.direction.toString()+"];");
	}
}
